<template>
  <div class>
    <el-card class="ep-card ep-search">
      <el-row :gutter="0">
        <el-col :span="2" style="float:right">
          <el-button type="success"  @click="save">保存</el-button>
        </el-col>
      </el-row>
    </el-card>

    <el-tabs type="border-card">

      <el-tab-pane label="原贷款情况">
        <originalLoanSituation ref="originalLoanSituation"></originalLoanSituation>
      </el-tab-pane>

      <el-tab-pane label="新贷款情况" name="1">
        <newLoanSituation ref="newLoanSituation"></newLoanSituation>
      </el-tab-pane>
      
    </el-tabs>
  </div>
</template>
<script>
export default {
  components: {
    originalLoanSituation: require("./bridgeCrossLoanOrigina.vue").default,
    newLoanSituation: require("./bridgeCrossLoanNew.vue").default
  },
  data() {
    return {
      projId:'',
      entName: '',
      bridCrossCz:false,
    };
  },
  computed: {},
  mounted() {},
  methods: {
    init(projId){
      this.projId=projId;
      let params={
        projectId:this.projId,
      }
      this.$api.formPost( 'biz/entBase/getEntNameByProjectId',params).then(res => {
        if(res.retHead.code="0000000"){
            this.entName = res.retBody;
            this.$refs.originalLoanSituation.assignment(this.entName);
            this.$refs.newLoanSituation.assignment(this.entName);
          }else{
              this.$message({
                  type: 'error',
                  message: res.retHead.message
              });
          }
      });
       //查询
       this.$api.formPost( 'biz/projBridCross/selectOriginalAndNewBridCross',{
        projId:projId
          }).then(res => {
                      if(res.retHead.code=="0000000"){
                           let bridCrossCz=false;
                          if(res.retBody.newBridCross){
                            this.$refs.newLoanSituation.bridCrossForm=res.retBody.newBridCross;
                            bridCrossCz=true;
                          }
                          if(res.retBody.originalBridCross){
                            this.$refs.originalLoanSituation.originaBridCrossForm=res.retBody.originalBridCross;
                            bridCrossCz=true;
                          }
                          this.bridCrossCz=bridCrossCz;
                        }else{
                            this.$message({
                                type: 'error',
                                message: res.retHead.message
                            });
                        }
          });
    },
    save() {
      //原贷款情况
      let originalBridCross = this.$refs.originalLoanSituation.getdata();
      //新贷款情况
      let newBridCross=this.$refs.newLoanSituation.getdata();
      let user=JSON.parse(sessionStorage.getItem("user"));
      originalBridCross.borrowEnt=this.entName;
      newBridCross.borrowEnt=this.entName;

      let params={
        originalBridCross:originalBridCross,
        newBridCross:newBridCross,
        projId:this.projId,
        createUserId:user.id,
        createUserName:user.realName,
      }
      if(!this.bridCrossCz){
          this.$api.post( 'biz/projBridCross/doSaveOriginalAndNewBridCross',params).then(res => {
              if(res.retHead.code=="0000000"){
                    this.$message({
                        type: 'success',
                        message: "保存成功"
                    });
                    //关闭弹框并清空数据
                    this.$refs.originalLoanSituation.clearForm();
                    this.$refs.newLoanSituation.clearForm();
                    this.$emit("hiddenComponent");
                }else{
                    this.$message({
                        type: 'error',
                        message: res.retHead.message
                    });
                }
            });
      }else{
          //更新
          this.$api.post( 'biz/projBridCross/doUpdateOriginalAndNewBridCross',params).then(res => {
              if(res.retHead.code=="0000000"){
                    this.$message({
                        type: 'success',
                        message: "更新成功"
                    });
                    //关闭弹框并清空数据
                    this.$emit("hiddenComponent");
                }else{
                    this.$message({
                        type: 'error',
                        message: res.retHead.message
                    });
                }
            });

      }
      
    }
  },
  created() {}
};
</script>
<style lang='scss' scoped>
</style>